package com.dyh.quickdemozwei.dyhTp;

import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yhdong
 * @Date: 2021/10/1 15:35
 */
public class DUtils {


    @Test
    public void test(){
        List<Foo> data = Lists.newArrayList(
                new Foo("A"),new Foo("A"),new Foo("A"),new Foo("B"),new Foo("B"),new Foo("C"),new Foo("B"),
                new Foo("A")
        );

        int diff = 4;
        List<Foo> [] matrix = new List[diff];
        for (int i = 0; i<diff;i++){
            matrix[i]=new ArrayList<>();
        }

        String lastRouteKey = "";
        int lastRouteIdx = 0;
        for (Foo datum : data) {
            if (!lastRouteKey.equals("")&&lastRouteKey.equals(datum.getCode()))
                 lastRouteIdx=(lastRouteIdx+1)&(diff-1);

                // lastRouteIdx=(lastRouteIdx+1)%diff;
            matrix[lastRouteIdx].add(datum);
            lastRouteKey = datum.getCode();
        }

        System.out.println();
    }
//    public static void main(String[] args) {
//
//    }
}
